Java Script


JavaScript is a programming language first developed by Netscape Communications. It is now standard on nearly every browser. You should know a few things about JavaScript right away:

  • It’s a real programming language.Don’t let anybody tell you otherwise. Sure, JavaScript doesn’t have all the same features as a monster, such as C++ or VB.NET, but it still has all the hallmarks of a complete programming language.

  • It’s not Java. Sun Microsystems developed a language called Java, which is also sometimes used in Web programming. Despite the similar names, Java and JavaScript are completely different languages. The original plan was for JavaScript to be a simpler language for controlling more complex Java applets, but that never really panned out.

  • It’s a scripting language.As programming languages go, JavaScript’s pretty friendly. It’s not quite as strict or wordy as some other languages. It also doesn’t require any special steps (such as compilation), so it’s pretty easy to use. These things make JavaScript a great first language.

Using JavaScript In HTML

JavaScript can be inserted into documents by using the SCRIPT tag:

Example:
<html>
 <head>
 <title>Hello World in JavaScript</title>
</head>
<body>
 <script type="text/javascript">
 document.write("Hello World!");
 </script>
</body>
</html>
 

Scripts can be placed in the HEAD or in the BODY
– In the HEAD, scripts are runbefore the page is displayed
– In the BODY, scripts are runas the page is displayed

Example:
<html>
  <head>
  <title>Hello World in JavaScript</title>
  <script type="text/javascript">
  function helloWorld() {
  document.write("Hello World!");}
  </script>
  </head>
 <body>
  <script type="text/javascript">
  helloWorld();
  </script>
 </body>
</html>


Scripts can also be loaded from an external file
-This is useful if you have a complicated script or
set of subroutines that are used in several different
documents.

<head>
<script src="myscript.js"></script>
</head>

There are three built-in methods of doing simple
user interaction in JavaScript
– alert(msg)alerts the user that somethinghas happened
– confirm(msg) asks the userto confirm (or cancel)
something
– prompt(msg, default) asks the userto enter some text

Know More

H T M L
C S S
P H P